import { initAuth } from "@/auth";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import ApiKeyManager from "@/components/ApiKeyManager";

export default async function ApiKeysPage() {
    const authInstance = await initAuth();
    // Fetch session using next/headers per better-auth docs for server components
    const session = await authInstance.api.getSession({ headers: await headers() });

    if (!session) {
        redirect("/"); // Redirect to home if no session
    }

    return (
        <div className="min-h-screen bg-gray-50">
            <div className="container mx-auto py-8 px-4">
                <div className="max-w-4xl mx-auto">
                    <div className="mb-8">
                        <h1 className="text-3xl font-bold text-gray-900">API Keys</h1>
                        <p className="text-gray-600 mt-2">
                            Manage your API keys for programmatic access to the terminal system
                        </p>
                    </div>
                    <ApiKeyManager />
                </div>
            </div>
        </div>
    );
}
